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, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1},
		{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1},
		{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
	}

	pl = {
		x = 35,
		y = 35,
		move = "",
		speed = 70,
		rotation = 0.9,
	}
end

function love.update(dt)
	local dwn = love.keyboard.isDown

	if dwn("up") and map[math.ceil((pl.y + math.sin(pl.rotation) * pl.speed * dt)/32)][math.ceil((pl.x + math.cos(pl.rotation) * pl.speed * dt)/32)] == 0 then
	pl.x = pl.x + math.cos(pl.rotation) * pl.speed * dt
	pl.y = pl.y + math.sin(pl.rotation) * pl.speed * dt end
	if dwn("left") then pl.rotation = pl.rotation - 5 * dt end
	if dwn("right") then pl.rotation = pl.rotation + 5 * dt end
end

function love.draw()
	love.graphics.setColor(1, 1, 1, 1)
	for j = 1, #map do
		for i = 1, #map[j] do
			if map[j][i] == 1 then
				love.graphics.rectangle("line", (i-1) * 4, (j-1) * 4, 4, 4)
			end
		end
	end

	xx = 0
	for fov = -225, 225 do	
		for c = 1, 2560 do	
			x = pl.x + math.cos(pl.rotation+math.rad(fov/5)) * c/5
			y = pl.y + math.sin(pl.rotation+math.rad(fov/5)) * c/5

			r = 15000/(c/5)


			if map[math.ceil(y/32)][math.ceil(x/32)] ~= 0 then
				love.graphics.setColor(1, 1, 1, 1)
				love.graphics.line(xx, 300 - r/2, xx, 300 + r/2)
				break
			end
		end
		xx = xx + (800/90)/5
	end

	love.graphics.setColor(1, 1, 1, 1)
	love.graphics.circle("line", pl.x/8, pl.y/8, 4)
	love.graphics.setColor(1, 0, 0, 1)
	love.graphics.line(pl.x/8, pl.y/8, (pl.x+(math.cos(pl.rotation))*100)/8, (pl.y+(math.sin(pl.rotation))*100)/8)
	love.graphics.print(love.timer.getFPS(), 400, 10)
	love.graphics.circle("line", 400, 300, 3)
end
